import { Temporal } from "@js-temporal/polyfill";

const currentTime = Temporal.Now.instant();
// Temporal.Now.timeZone()
// Temporal.Now.zonedDateTime(calendar) Temporal.Now.zonedDateTimeISO()
// Temporal.Now.plainDateTime(calendar) Temporal.Now.plainDateTimeISO()
// Temporal.Now.plainDate(calendar) Temporal.Now.plainDateISO()
// Temporal.Now.plainTimeISO()

const instant = Temporal.Instant.from('1969-07-20T20:17Z');
const zonedDateTime = Temporal.ZonedDateTime.from({
  timeZone: 'America/Los_Angeles',
  year: 1995,
  month: 12,
  day: 7,
  hour: 3,
  minute: 24,
  second: 30,
  millisecond: 0,
  microsecond: 3,
  nanosecond: 500
});
const dateTime = Temporal.PlainDateTime.from({
  year: 2018,
  month: 2,
  day: 10,
  hour: 8,
  minute: 12,
  second: 48,
});
const date = Temporal.PlainDate.from({ year: 2006, month: 8, day: 24 });
const time = Temporal.PlainTime.from({
  hour: 19,
  minute: 39,
  second: 9,
  millisecond: 68,
  microsecond: 346,
  nanosecond: 205
});
const newDateTime = dateTime.add({ months: 1 });
const yearMonth = Temporal.PlainYearMonth.from({ year: 2020, month: 10 });
const monthDay = Temporal.PlainMonthDay.from({ month: 7, day: 14 }); // => 07-14
const date = monthDay.toPlainDate({ year: 2030 });
const duration = Temporal.Duration.from({
  hours: 130,
  minutes: 20
});
duration.total({ unit: 'second' });
const cal = Temporal.Calendar.from('iso8601');
const date = cal.dateFromFields({ year: 1999, month: 12, day: 31 }, {});

const timeZone = Temporal.TimeZone.from('Africa/Cairo');
timeZone.getInstantFor('2000-01-01T00:00'); // => 1999-12-31T22:00:00Z
timeZone.getPlainDateTimeFor('2000-01-01T00:00Z'); // => 2000-01-01T02:00:00
timeZone.getPreviousTransition(Temporal.Now.instant()); // => 2014-09-25T21:00:00Z
timeZone.getNextTransition(Temporal.Now.instant()); // => null

console.log(currentTime.toString());
console.log(currentTime.toZonedDateTimeISO(new Temporal.TimeZone("Asia/Shanghai")).toString());
console.log("milliseconds: ", currentTime.epochMilliseconds);
console.log("nanoseconds: ", currentTime.epochNanoseconds);
console.log(`${dt1.year}/${dt1.month}/${dt1.day}`);

const dt1 = Temporal.PlainDate.from("2023-02-01");
const dt2 = Temporal.PlainDate.from("2023-02-05");
const diff = dt2.since(dt1);
console.log(diff.days);
// Temporal.TimeZone Temporal.ZonedDateTime
// Temporal.Calendar Temporal.PlainDateTime
